<?php
session_start();
if(isset($_SESSION['admin_id'])) {
    $mes="";
    if (isset($_SESSION['mes'])) {
        $mes = $_SESSION['mes'];
        $_SESSION['mes']="";
    }
    include ("../include/menu.php");
    include ("../include/dbFunctions.php");
    if (isset($_POST['from'])&&isset($_POST['to'])){
        $from=$_POST['from'];
        $to=$_POST['to'];
        $query = "
SELECT DISTINCT v.volunteer_firstname, v.volunteer_surname, .v.volunteer_email, e.event_name, sc.school_name, p.program_name
FROM event e, volunteer v, trainer t, school sc, program p,session s
WHERE e.event_id = t.event_id
AND t.volunteer_id = v.volunteer_id
AND e.event_id = s.event_id
AND e.school_id = sc.school_id
AND p.program_id=e.program_id
AND t.trainer_status='confirmed'
AND s.session_date
BETWEEN '$from'
AND '$to'
ORDER BY v.volunteer_firstname";
    $report_array = executeSelectQuery($query);
$query1 = "
SELECT DISTINCT v.volunteer_id, v.volunteer_firstname,
v.volunteer_surname, e.event_name,sc.school_name
FROM event e, volunteer v, trainer t,school sc,
SESSION s
WHERE e.event_id = t.event_id
AND t.volunteer_id = v.volunteer_id
AND e.event_id = s.event_id
AND e.school_id = sc.school_id
AND t.trainer_status='confirmed'
AND s.session_date
BETWEEN '$from'
AND '$to'";
    $report_array1 = executeSelectQuery($query1);
    }
    
    ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>JA Scheduling</title>

        <!--Embed CSS Scripts!-->
        <style type="text/css" title="currentStyle">
            @import "../media/css/jquery-ui-1.8.13.custom.css";
            @import "../media/css/dataTable.css";
            @import "../media/css/TableTools.css";
            @import "../media/css/screen.css";

            #filter_options select{
                display: block;
            }
        </style>

        <!--Embed Javascripts-->
        <script type="text/javascript" src="../media/js/jquery/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="../media/js/jquery/jquery-ui-1.8.13.custom.js"></script>
        <script type="text/javascript" src="../media/js/jquery/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="../media/js/jquery/ajaxReloadDataTable.js"></script>
        <script type="text/javascript" src="../media/js/jquery/jquery.validate.js"></script>
        <script type="text/javascript" src="../media/js/jquery/TableTools.js"></script>
        <script type="text/javascript" src="../media/js/jquery/ZeroClipboard.js"></script>
        <script type="text/javascript" src="../media/js/highcharts.src.js"></script>
        <script type="text/javascript" src="../media/js/chart/volunteerChartOptions.js"></script>


        <!--Onsite scripts!-->
        <script type="text/javascript">

            var oTable; //Initialize DataTables object, make it global
            var volunteer_education_chart;//Setup variabe make global

            $(document).ready(function() {
                $('#admintable').dataTable( {
                    "sPaginationType": "full_numbers"
                } );

                $('#from,#to').datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: 'yy-mm-dd'
                });

            });
        </script>



    </head>

    <body>

        <!-- DON'T TOUCH! Start: page-top-outer -->
            <?php
            top_outer();
            ?>
        <!-- End: page-top-outer -->

        <div class="clear">&nbsp;</div>

        <!--  start nav-outer-repeat................................................................................................. START -->
        <div class="nav-outer-repeat">
            <!--  start nav-outer -->
            <div class="nav-outer">

                <!-- start nav-right -->
                    <?php
                    nav_right();
                    ?>
                <!-- end nav-right -->


                <!--  start nav -->
                <div class="nav">
                    <div class="table">

                            <?php
                            navigation_report();
                            ?>

                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                </div>
                <!--  start nav -->

            </div>
            <div class="clear"></div>
            <!--  start nav-outer -->
        </div>
        <!--  start nav-outer-repeat................................................... END -->

        <div class="clear"></div>

        <!-- start content-outer ........................................................................................................................START -->
        <div id="content-outer">
            <!-- start content -->
            <div id="content">

                <!--  start page-heading --> <!--lyedit-->
                <div id="page-heading">
                    <h1>Volunteer Reports</h1>
                </div>
                <!-- end page-heading -->

                <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                    <tr>
                        <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                        <th class="topleft"></th>
                        <td id="tbl-border-top">&nbsp;</td>
                        <th class="topright"></th>
                        <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                    </tr>
                    <tr>
                        <td id="tbl-border-left"></td>
                        <td>
                            <!--  start content-table-inner ...................................................................... START -->
                            <div id="content-table-inner">
                                <table width="100%">
                                    <td align="right">
                                            <table>
                                                <tr><td>
                                                        <input type="button" value="&nbsp;" class="volunteer-report" onClick="parent.location='volunteerReport.php'"></input>
                                                    </td>
                                                    <td>
                                                        <input type="button" value="&nbsp;" class="school-report" onClick="parent.location='schoolReport.php'"></input>
                                                    </td>
                                                    
                                                    <td>
                                                        <input type="button" value="&nbsp;" class="course-report" onClick="parent.location='eventReport.php'"></input>
                                                    </td>
                                                </tr>
                                            </table>

                                        </td>
                                </table>
                                <div id="table-content">
                                <h2></h2>
                                <!--  start table-content  -->
                                <div id="volunteerReporContents">
                                    <h3>Select Options</h3>
                                    <div id="filter_options">
                                    <form name="choose_date" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" id ="school">
                                    
                                        <label for="from">From</label>
                                        <input type="text" id="from" name="from"/>
                                        <label for="to">to</label>
                                        <input type="text" id="to" name="to"/>
                                        <br/>
                                        <br/>
                                        <input type="submit" id="submit" value="&nbsp;" class="form-submit"/>
                                        <br/><br/><br/>
</form> 
                                    </div><!--End of #filter_options!-->

                                        <h3>Result</h3>
                                        <?php
                                        if (isset($_POST['from'])&&isset($_POST['to'])){
                                            ?>
                                        <table cellpadding="0" cellspacing="0" border="0" class="display" id="admintable">
                                            <thead>
                                                <tr>

                                                    <th>Volunteer Firstname</th>
                                                    <th>Volunteer Surname</th>
                                                    <th>Volunteer Email</th>
                                                    <th>Course taught</th>
                                                    <th>Program name</th>
                                                    <th>School</th>

                                                </tr>
                                            </thead>
                                            <tbody>
                                                    <?php
                                                    for ($i=0;$i<count($report_array);$i++) {
                                                        $id=$report_array1[$i]['volunteer_id'];
                                                        $no = $i+1;
                                                        $firstname = $report_array[$i]['volunteer_firstname'];
                                                        $surname =$report_array[$i]['volunteer_surname'];
                                                        $email =$report_array[$i]['volunteer_email'];
                                                        $eventname =$report_array[$i]['event_name'];
                                                        $schoolname =$report_array[$i]['school_name'];
                                                        $programname = $report_array[$i]['program_name'];
                                                        $today=date("Y-m-d H:i:s");
                                                        $report_title="VOLUNTEER REPORT $today";

                                                        echo "<td><a href='../volunteer/volunteerView.php?id=".$id."'>$firstname</a></td>";
                                                        echo "<td>$surname</td>";
                                                        echo "<td><a href=$email>$email</a></td>";
                                                        echo "<td>$eventname</td>";
                                                        echo "<td>$programname</td>";
                                                        echo "<td>$schoolname</td>";
                                                        echo "</tr>";
                                                    }
                                                    ?>
                                            </tbody>
                                        </table><br/><br/><br/>
                                        <form name="query" method="post" action="testexport.php">
                                           <input name="from" value="<?php echo $from?>" type="hidden"></input>
                                           <input name="to" value="<?php echo $to?>" type="hidden"></input>
                                           <input name="query" value="<?php echo $query?>" type="hidden"></input>
                                           <input name="report_title" value="<?php echo $report_title?>" type="hidden"></input>
                                           <input type="submit" value="&nbsp;" onclick="window.location.replace('testexport.php')" class="form-excel"/>
                                        </form>
                                        <?php
                                        }else{
                                            ?>
                                        <table cellpadding="0" cellspacing="0" border="0" class="display" id="volunteerTable">
                                            <thead>
                                                <tr>
                                                    <th>Volunteer Name</th>
                                                    <th>From</th>
                                                    <th>No. participated Programs</th>
                                                    <th>No. participated Events</th>
                                                    <th>No. Schools volunteered</th>
                                                </tr>
                                            </thead>

                                            <tbody>
                                                <tr>
                                                    <td colspan="5" class="dataTables_empty">Please choose options and click on Submit</td>
                                                </tr>
                                            </tbody>
                                        </table>
                                        <?php
                                        }
                                        ?>



                                </div><!--End of #volunteerReporContents!-->


                                <div class="clear"></div>
                            </div>
                            </div>
                            <!--  end content-table-inner ............................................END  -->
                        </td>
                        <td id="tbl-border-right"></td>
                    </tr>
                    <tr>
                        <th class="sized bottomleft"></th>
                        <td id="tbl-border-bottom">&nbsp;</td>
                        <th class="sized bottomright"></th>
                    </tr>
                </table>
                <div class="clear">&nbsp;</div>

            </div>
            <!--  end content -->
            <div class="clear">&nbsp;</div>
        </div>
        <!--  end content-outer........................................................END -->
            <?php
            footer();
            ?>

    </body>
</html>
    <?php
}else {
    header("Location: ../include/login.html");
}
?>